//
// Created by Administrator on 2023-10-5
// 链表反转
//

#include <iostream>

using namespace std;

struct Node
{
    int value;
    Node *next;

    // 构造函数
    Node(int v, Node *n = nullptr)
    {
        value = v;
        next = n;
    }

    Node()
    {
        value = 0;
        next = nullptr;
    }
};

int main()
{
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//    int arr[] = {1, 2, 3};
    Node *head = new Node();
    Node *cur = head;
    for (int i : arr)
    {
        Node *t = new Node(i,NULL);
//        t->value=i;
//        t->next= nullptr;
        cur->next = t;
        cur = cur->next;
    }
    // 打印链表,让cur重新指向头结点的后边
//    cur=head->next;
//    while(cur!=nullptr)
//    {
//        cout<<cur->value;
//        cur=cur->next;
//    }
    Node *p1 = new Node();
    Node *p2 = new Node();
    p1->next = head;
    p2 = head;
    // p1 p2 地址不一样
    cout << endl << p1 << endl << p2 << endl;
    // 链表反转
    cur = head->next;
    Node *p = nullptr;
    Node *n = cur->next;
    while (n)
    {
        cur->next=p;
        head->next=cur;
        p=cur;
        cur=n;
        n=n->next;
    }
    cur->next=p;
    head->next=cur;
    // 打印链表,让cur重新指向头结点的后边
    cur=head->next;
    while(cur!=nullptr)
    {
        cout<<cur->value;
        cur=cur->next;
    }
    return 0;
}